package com.soccertgc
{
	
	public class VersionType
	{
			
		// -------------------------------------------------------------------------------
		// CONSTANTS
		// -------------------------------------------------------------------------------              
		
		public static const RELEASE:VersionType				= new VersionType(0, "",		"Release");
		public static const ALPHA:VersionType               = new VersionType(1, "(alpha)",	"Alpha");
		public static const BETA:VersionType                = new VersionType(2, "(beta)",	"Beta");
		
		// -------------------------------------------------------------------------------
		// STATIC
		// -------------------------------------------------------------------------------
		
		private static var _initialized:Boolean = false;
		private static var _list:Vector.<VersionType>;
		
		// Fake static constructor
		{
			// Fill the internal list
			_list = new Vector.<VersionType>();
			_list.push(RELEASE);
			_list.push(ALPHA);
			_list.push(BETA);
			// Init!
			_initialized = true;
		}
		
		// -------------------------------------------------------------------------------
		// FIELDS
		// -------------------------------------------------------------------------------
		
		private var _id:uint;
		private var _name:String;
		private var _sign:String;
		
		// -------------------------------------------------------------------------------
		// CONSTRUCTORS
		// -------------------------------------------------------------------------------
		
		public function VersionType(id:uint, sign:String, name:String)
		{
			// Safe unique instance lock
			if (_initialized) throw new Error("VersionType enum already created!");
			// Init
			_id   = id;
			_sign = sign;
			_name = name;
		}
		
		// -------------------------------------------------------------------------------
		// PROPERTIES
		// -------------------------------------------------------------------------------              
		
		public function get id():uint
		{
			return _id;
		}
		
		public function get name():String
		{
			return _name;
		}
		
		public function get sign():String
		{
			return _sign;
		}
		
		// -------------------------------------------------------------------------------
		// STATIC METHODS
		// -------------------------------------------------------------------------------
		
		/**
		 * Returns the list of the names of the game sides
		 * @return List of the names of the game sides
		 */
		public static function names():Array
		{
			var list:Array  = new Array();
			// Loop over values list
			for (var i:int=0; i<_list.length; i++)
			{
				list.push(_list[i].name);
			}
			return list;
		}
		
		/**
		 * 
		 * @return 
		 */
		public static function list():Array
		{
			var list:Array = new Array;
			// Loop over values list
			for (var i:int=0; i<_list.length; i++)
			{
				list.push(_list[i]);
			}
			return list;
		}
		
		/**
		 * Search a VersionType by given id 
		 * @param id Id of the log target to find
		 * @return VersionType constant for the given id, null if no VersionType
		 * for the given id has been found
		 */             
		public static function getById(id:uint):VersionType
		{
			// Search the value into the list
			for (var i:int=0; i<_list.length; i++)
			{
				if (_list[i].id == id) return _list[i];
			}
			throw new Error("VersionType for id '" + id + "' unknown!");
		}
		
		/**
		 * Search a VersionType by given name 
		 * @param name Name of the log target to find
		 * @return VersionType constant for the given id, null if no VersionType
		 * for the given name has been found
		 */             
		public static function getByName(name:String):VersionType
		{
			// Search the value into the list
			for (var i:int=0; i<_list.length; i++)
			{
				if (_list[i].name == name) return _list[i];
			}
			throw new Error("VersionType for name '" + name + "' unknown!");
		}
		
		/**
		 * Search a VersionType by given sign 
		 * @param name sign of the player VersionType to find
		 * @return PlayerVersionType constant for the given id, null if no VersionType
		 * for the given sign has been found
		 */		
		public static function getBySign(sign:String):VersionType
		{
			if (sign == null || sign == "") return RELEASE;
			// Search the value into the list
			for (var i:int=0; i<_list.length; i++)
			{
				if (_list[i].sign == sign) return _list[i];
			}
			throw new Error("VersionType for sign '" + sign + "' unknown!");
		}

	}

}